
#include <BListWidget>
#include <BListItem>
#include "member_BListWidget.h"
#include "member_BListItem.h"

using namespace BWE;

#define member					(*(member_BListItem*)_ptr)
#define member_allocate()		_ptr = new member_BListItem(this)
#define member_release()		delete (member_BListItem*)_ptr
#define layout_member(listWidget)	((member_BListWidget*)listWidget->_ptr)

BListItem::BListItem(BListWidget* listWidget)
{
	member_allocate();
	if(listWidget)
		listWidget->addItem(this);
}
BListItem::BListItem(const BString& text, BListWidget* listWidget)
{
	member_allocate();
	this->setText(text);
	if(listWidget)
		listWidget->addItem(this);
}
BListItem::BListItem(BImage* image, const BString& text, BListWidget* listWidget)
{
	member_allocate();
	this->setImage(image);
	this->setText(text);
	if(listWidget)
		listWidget->addItem(this);
}
BListItem::~BListItem()
{
	member_release();
}

void BListItem::setAlign(Align align)
{
	if (member.align != align)
	{
		member.align = align;
		member.dirtyCell();
	}
}
Align BListItem::align() const
{
	return member.align;
}

void BListItem::setText(const BString& text)
{
	if (member.text != text)
	{
		member.text = text;
		member.dirtyCell();
		emit(Signal_TextChanged, member.text);
	}
}
const BString& BListItem::text() const
{
	return member.text;
}

void BListItem::setImage(BImage* image)
{
	if (member.image != image)
	{
		member.image = image;
		member.dirtyCell();
		emit(Signal_ImageChanged, member.image);
	}
}
BImage* BListItem::image()
{
	return member.image;
}
const BImage* BListItem::image() const
{
	return member.image;
}

void BListItem::setValue(const BValue& value)
{
	if (member.value != value)
	{
		member.value = value;
	}
}
const BValue& BListItem::value() const
{
	return member.value;
}

void BListItem::setThing(BThing* thing)
{
	if (member.thing != thing)
	{
		member.thing = thing;
		emit(Signal_ThingChanged, thing);
	}
}
BThing* BListItem::thing()
{
	return member.thing;
}
const BThing* BListItem::thing() const
{
	return member.thing;
}

void BListItem::setSelected(bool selected)
{
	if (member.list && member.selected != selected)
	{
		member.list->setSelected(this, selected);
	}
}
bool BListItem::isSelected() const
{
	return member.list && member.selected;
}

BRect BListItem::rect() const
{
	return member.rect;
}
bool BListItem::visible() const
{
	return member.visible;
}
